﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace quanlysinhvien
{
    public partial class FrmAddUser : Form
    {
        SqlConnection conn;

        public FrmAddUser()
        {
            InitializeComponent();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtUsername.Text == "")
            {
                MessageBox.Show("Please insert Username");
            }
            else
            {
                //insert
                conn = Connect.getConnection();
                conn.Open();
                string sql = "insert into TblUser(Username,Password) values('" + txtUsername.Text + "','" + txtPassword.Text + "')";
                SqlCommand cmd = new SqlCommand(sql, conn);
                SqlDataReader dr = cmd.ExecuteReader();
                conn.Close();
                MessageBox.Show("OK, Saved to database");
                txtUsername.Text = "";
                txtPassword.Text = "";
                txtUsername.Focus();
            }
        }

        private void btnReset_Click(object sender, EventArgs e)
        {
            txtUsername.Text = "";
            txtPassword.Text = "";
            txtUsername.Focus();
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            FrmUserManagement FrmUserManagement = new FrmUserManagement();
            FrmUserManagement.Show();
            this.Hide();
        }
    }
}
